﻿using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Zocono.Infrastructure.Common;
using Zocono.WCS.Application.AppConfigureManage;
using Zocono.WCS.Application.AppHynnStateUp;
using Zocono.WCS.Application.AppLogManage;
using Zocono.WCS.Application.AppPlcManage;
using Zocono.WCS.Domain.BytesMapObjectDomain;
using Zocono.WCS.Domain.DomainRepository;
using Zocono.WCS.Domain.ElevatorManage;
using Zocono.WCS.Domain.EquipmentProcessDomain;
using Zocono.WCS.Domain.EquipmentProcessDomain.ElevatorMessage;
using Zocono.WCS.Domain.EquipmentProcessDomain.PlanarGeneralMessage;
using Zocono.WCS.Domain.EquipmentProcessDomain.PlanarMessage;
using Zocono.WCS.Domain.EquipmentProcessDomain.ScMessage;
using Zocono.WCS.Domain.FSJDomain;
using Zocono.WCS.Domain.HynnStateUpDomain;
using Zocono.WCS.Domain.JobExcutorDomain;
using Zocono.WCS.Domain.LogDomain;
using Zocono.WCS.Domain.MonitorDomain;
using Zocono.WCS.Domain.PlcBytesObject;
using Zocono.WCS.Domain.PlcConnectPoolDomain;
using Zocono.WCS.Domain.PlcPointDomain;
using Zocono.WCS.Domain.PlcReadDbDomain;
using Zocono.WCS.Domain.PlcWriteBoMangeDomain;
using Zocono.WCS.Domain.PlcWriteDbDomain;
using Zocono.WCS.Domain.ProcessModuleDomain;
using Zocono.WCS.Domain.ProgrameDomain;
using Zocono.WCS.Domain.RouteDomain;
using Zocono.WCS.Domain.ScGetWMSTaskDomain;
using Zocono.WCS.Domain.ScWorkModelDomain;
using Zocono.WCS.Domain.SocketServiceDomain;
using Zocono.WCS.Domain.StationDomain;
using Zocono.WCS.Domain.WcsGetWmsJobDomain;
using Zocono.WCS.Domain.WorkTaskDomain;
using Zocono.WCS.Infrastructure.Repository;
using Zocono.WCS.WMSApiDomain.WebApi;

namespace Zocono.WCS.HangfireHost
{
    public static class ServiceIOC
    {
        public static void AddService(IServiceCollection services)
        {
            //系统服务雪花ID，单例
            services.AddSingleton<ISnowflake, Snowflake>();
            //PLC连接池 单例
            services.AddSingleton<IPlcConnectionPool, PlcConnectionPool>();
            //线程池封装服务，外部类注入使用
            services.AddScoped<IPlcConnectionPoolService, PlcConnetionPoolService>();
            //仓储
            services.AddScoped<IProgrameInfoRepository, ProgrameInfoRepository>();
            services.AddScoped<IJobInfoRepository, JobInfoRepository>();
            services.AddScoped<IPlcConnectionInfoRepository, PlcConnectionInfoRepository>();
            services.AddScoped<IPlcReadDbInfoRepository, PlcReadDbInfoRepository>();
            services.AddScoped<IPlcConnectionLockInfoRepository, PlcConnectionLockInfoRepository>();
            services.AddScoped<IPlcConnectionStateInfoRepository, PlcConnectionStateInfoRepository>();
            services.AddScoped<IPlanarProcessServiceMapInfoRepository, PlanarProcessServiceMapInfoRepository>();
            services.AddScoped<ITaskRouteDetailRecordInfoRepository, TaskRouteDetailRecordInfoRepository>();
            services.AddScoped<ITelegramRecordInfoRepository, TelegramRecordInfoRepository>();
            services.AddScoped<IScWorkModelInfoRepository, ScWorkModelInfoRepository>();

            //日志
            services.AddScoped<IInterfaceLogRepository, InterfaceLogRepository>();
            services.AddScoped<IRunLogRepository, RunLogRepository>();
            services.AddScoped<IRunLogInfoService, RunLogInfoService>();
            services.AddScoped<IInterfaceLogInfoService, InterfaceLogInfoService>();
            services.AddScoped<LogApp>();
            services.AddScoped<IOperateLogService, OperateLogService>(); 
            services.AddScoped<IOperateLogInfoRepository, OperateLogInfoRepository>(); 

            //服务，启动程序管理
            services.AddScoped<IProgrameService, ProgrameService>();
            //服务，Job
            services.AddScoped<IBytesMapObjectInfoRepository, BytesMapObjectInfoRepository>();
            services.AddScoped<IBytesMapObjectService, BytesMapObjectService>();
            services.AddScoped<IReadDbJobService, ReadDbJobService>();
            services.AddScoped<IJobExcutorService, JobExcutorService>();
            //服务，报文类工厂
            services.AddScoped<IBytesObjectServiceFactory, BytesObjectServiceFactory>();//报文工厂
            //报文实体
            services.AddScoped<BytesObjectBase, PlcOnLineStateBO>();//平面PLC在线状态
            services.AddScoped<BytesObjectBase, PlanarStateBO>();//平面设备状态
            services.AddScoped<BytesObjectBase, PlanarGeneralWcsActionBO>();//平面设备正常WCS动作报文
            services.AddScoped<BytesObjectBase, PlanarGeneralPlcActionBO>();//平面设备正常PLC动作报文
            services.AddScoped<BytesObjectBase, PlanarBatteryScanPlcActionBO>();//平面设备电池条码扫码动作报文
            services.AddScoped<BytesObjectBase, ZJNScMessagePlcActionBO>();
            services.AddScoped<BytesObjectBase, ZJNScMessageWcsActionBO>();
            services.AddScoped<BytesObjectBase, QTScMessagePlcActionBO>();
            services.AddScoped<BytesObjectBase, QTScMessageWcsActionBO>();
            services.AddScoped<BytesObjectBase, PlanarInventoryBO>();
            services.AddScoped<BytesObjectBase,PlanarGeneralPlcActionBOFx>(); //"PlanarGeneralPlcActionBOFx"平面设备分选正常WCS动作报文

            //services.AddScoped<WCSMessageWithWMSApi>();

            //服务，处理模型服务工厂
            services.AddScoped<IProcessModuleServiceFactory, ProcessModuleServiceFactory>();//处理模型服务工厂
            //服务，处理模型服务
            services.AddScoped<IProcessMuduleService, ProcessModulePlanarService>();//处理平面报文模型服务
            services.AddScoped<IProcessMuduleService, ProcessModulePlanarFxService>();//处理平面报文模型服务

            services.AddScoped<IProcessMuduleService, ProcessModuleScService>();//处理SC报文模型服务
            //服务, 平面/SC 报文业务服务
            services.AddScoped<IProcessPlanarService, ProcessPlanarService>();//平面报文处理入口
            //服务, 平面报文（PLC状态、状态、动作）业务服务工厂
            services.AddScoped<IPlanarMessageServiceFactory, PlanarMessageServiceFactory>();//平面报文处理服务工厂
            //服务, 平面报文（PLC状态、状态、动作）业务服务
            services.AddScoped<IPlanarStateMessageService, PlanarStateBOMessageService>();//平面状态报文处理
            services.AddScoped<IPlanarActionMessageService, PlanarGeneralPlcActionBOMessageService>();//平面正常报文交互服务
            services.AddScoped<IPlanarActionMessageService, PlanarGeneralPlcActionBOFxMessageService>();//平面分选机报文交互服务

            services.AddScoped<IPlanarActionMessageService, PlanarBatteryScanPlcActionBOMessageService>();//平面特殊报文-组盘业务


            //服务，平面正常动作报文业务处理服务工厂
            services.AddScoped<IPlanarGeneralPlcActionProcessServiceFactory, PlanarGeneralPlcActionProcessServiceFactory>();//工厂
            services.AddScoped<IDispatchEquipmentPlanarStateRepository, DispatchEquipmentPlanarStateRepository>();
            services.AddScoped<IDispatchEquipmentRepository, DispatchEquipmentRepository>();


            services.AddScoped<IElevatorInfoRepository, ElevatorInfoRepository>();
            services.AddScoped<IElevatorJudgeInfoRepository, ElevatorJudgeInfoRepository>();
            services.AddScoped<IElevatorMasterInfoRepository, ElevatorMasterInfoRepository>();


            //服务，平面正常动作报文业务处理服务实现
            services.AddScoped<IPlanarGeneralPlcActionProcessService, AisleRequestService>();//巷道申请
            services.AddScoped<IPlanarGeneralPlcActionProcessService, AisleRequest1Service>();//条件巷道申请
            services.AddScoped<IPlanarGeneralPlcActionProcessService, AisleLocationRequestService>();//货位申请
            services.AddScoped<IPlanarGeneralPlcActionProcessService, ArriveDoNoTaskCodeService>();//
            services.AddScoped<IPlanarGeneralPlcActionProcessService, ArriveDoService>();//出库台处理
            services.AddScoped<IPlanarGeneralPlcActionProcessService, UnBindingService>();//解绑业务
            services.AddScoped<IPlanarGeneralPlcActionProcessService, UnBinding1Service>();//无条件解绑业务
            services.AddScoped<IPlanarGeneralPlcActionProcessService, ArrivePuService>();//入库台业务
            services.AddScoped<IPlanarGeneralPlcActionProcessService, ArriveTargetService>();//到达目标结束任务
            services.AddScoped<IPlanarGeneralPlcActionProcessService, ClearDataService>();//清除报文
            services.AddScoped<IPlanarGeneralPlcActionProcessService, FreeDataService>();//
            services.AddScoped<IPlanarGeneralPlcActionProcessService, WaitActionService>();//
            services.AddScoped<IPlanarGeneralPlcActionProcessService, ArriveDDService>();//提升机业务
            services.AddScoped<IPlanarGeneralPlcActionProcessService, ArriveTsjService>();//提升机业务-新逻辑
            services.AddScoped<IPlanarGeneralPlcActionProcessService, ArriveDDDService>();//提升机业务-新逻辑
            services.AddScoped<IPlanarGeneralPlcActionProcessService, ArriveDoFinishTaskService>();
            services.AddScoped<IPlanarGeneralPlcActionProcessService, CountCheckService>();//CCD数量检测
            services.AddScoped<IPlanarGeneralPlcActionProcessService, ScanPalletMoveService>(); //询问目标位置
            services.AddScoped<IPlanarGeneralPlcActionProcessService, ScanBandingService>(); //绑盘机
            services.AddScoped<IPlanarGeneralPlcActionProcessService, FeedingPortService>(); //绑盘机FeedingPortService
            services.AddScoped<IPlanarGeneralPlcActionProcessService, ElevatorRouteService>();  //ElevatorRouteService
            services.AddScoped<IPlanarGeneralPlcActionProcessService, EleNextStateService>();  //ElevatorRouteService
            services.AddScoped<IPlanarGeneralPlcActionProcessService, ResetCheckDataService>();//清除报警报文
            services.AddScoped<IPlanarGeneralPlcActionProcessService, BatteryMidwayTargetRequestService>();//中途申请目标位
            services.AddScoped<IPlanarGeneralPlcActionProcessService, FourContainerCodeCheckService>();//四码校验
            services.AddScoped<IPlanarGeneralPlcActionProcessService, BatteryCheckInfoService>();//电芯校验业务


            services.AddScoped<IPlanarGeneralPlcActionProcessService, DrumpOutProcessService>();//分选机挑选位置跳过流程实例节点
            services.AddScoped<IPlanarGeneralPlcActionProcessService, FenXuanNgUploadService>();//分选机挑选位置 挑选完剩余电芯上报
            services.AddScoped<IPlanarGeneralPlcActionProcessService, FSJWorker_1Service>();//分选机业务
            services.AddScoped<IPlanarGeneralPlcActionProcessService, FSJWorker_2Service>();//分选机业务
            services.AddScoped<IPlanarGeneralPlcActionProcessService, FSJWorker_ZuPan_1Service>();//分选机业务
            services.AddScoped<IPlanarGeneralPlcActionProcessService, FSJWorker_ZuPan_2Service>();//分选机业务
            services.AddScoped<IFSJMesService, FSJMesService>();//分选机Mes业务



            //路径配置
            services.AddScoped<RouteInfoApp>();
            services.AddScoped<IRouteInfoRepository, RouteInfoRepository>();
            services.AddScoped<IRouteInfoService, RouteInfoService>();

            //路径明细配置
            services.AddScoped<RouteDetailInfoApp>();
            services.AddScoped<IRouteDetailInfoRepository, RouteDetailInfoRepository>();
            services.AddScoped<IRouteDetailInfoService, RouteDetailInfoService>();


            //plc 读db 配置
            services.AddScoped<IPlcReadDbInfoRepository, PlcReadDbInfoRepository>();
            services.AddScoped<IPlcReadDbInfoService, PlcReadDbInfoService>();
            services.AddScoped<PlcReadDbInfoApp>();

            //plc 写db 配置
            services.AddScoped<IPlcWriteDbInfoRepository, PlcWriteDbInfoRepository>();
            services.AddScoped<IPlcWriteDbInfoService, PlcWriteDbInfoService>();
            services.AddScoped<PlcWriteDbInfoApp>();

            //报文解析配置
            services.AddScoped<IBytesMapObjectInfoRepository, BytesMapObjectInfoRepository>();
            services.AddScoped<IBytesMapObjectInfoService, BytesMapObjectInfoService>();
            services.AddScoped<BytesMapObjectInfoApp>();
            //工位信息配置
            services.AddScoped<StationInfoApp>();
            services.AddScoped<IStationInfoRepository, StationInfoRepository>();
            services.AddScoped<IStationInfoService, StationInfoService>();

            //PLC点位配置
            services.AddScoped<IPlcPointInfoRepositpry, PlcPointInfoRepository>();
            services.AddScoped<IPlcPointInfoService, PlcPointInfoService>();
            services.AddScoped<IPlcPointInfoService,PlcPointInfoService>();


            services.AddScoped<IProcessScService, ProcessScService>();
            services.AddScoped<IScMessageServiceFactory, ScMessageServiceFactory>();
            services.AddScoped<IWorkTaskInfoRepository, WorkTaskInfoRepository>();
            services.AddScoped<IPlcWriteDbInfoRepository, PlcWriteDbInfoRepository>();

            //WMS下发 WCS作业EmptyPalletMoveService
            services.AddScoped<IWcsGetWmsJobService, WcsGetWmsJobService>();
            //services.AddScoped<IWorkTaskInfoRepository, WorkTaskInfoRepository>();
            services.AddScoped<IRouteInfoRepository, RouteInfoRepository>();
            services.AddScoped<IRouteDetailInfoRepository, RouteDetailInfoRepository>();

            //
            services.AddScoped<IScActionMessageService, ZJNScActionMessageService>();
            services.AddScoped<IScActionMessageService, QTScActionMessageService>();
            services.AddScoped<IScGetWMSTaskService, ScGetWMSTaskService>();
            services.AddScoped<IScWorkModelService, ScWorkModelService>();


            services.AddScoped<IElevatorInfoService, ElevatorInfoService>();
            services.AddScoped<IElevatorJudgeInfoService, ElevatorJudgeInfoService>();
            services.AddScoped<IElevatorMasterInfoService, ElevatorMasterInfoService>();



            services.AddScoped<ISocketClientInfoRepository, SocketClientInfoRepository>();
            services.AddScoped<ISocketClientInfoService, SocketClientInfoService>();

            services.AddScoped<PlcWriteBoMange>();
            services.AddScoped<IPlcWriteBoService, PlcWriteBoService>();
            //监控
            services.AddScoped<IMonitorConfigInfoRepository, MonitorConfigInfoRepository>();
            services.AddScoped<IMonitorConfigInfoService, MonitorConfigInfoService>();


            //WMS手动解绑通知WCS手动完成任务
            services.AddScoped<WorkTaskInfoApp>();
            services.AddScoped<IWorkTaskInfoServeice, WorkTaskInfoServeice>();
            //恒翼能设备状态保存
            services.AddScoped<HynnStateUpApp>();
            services.AddScoped<IHynnStateUpService, HynnStateUpService>();
            
        }
    }
}
